package com.dong.Arrays.arithemtic;

import java.util.Arrays;

/*
输入：target = 7, nums = [2,3,1,2,4,3]
输出：2
解释：子数组 [4,3] 是该条件下的长度最小的 连续子数组子数组。
 */
public class Test {

    public static void main(String[] args) {
        int [] nums = {0,1,2,2,3,0,4,2};
        int val = 2;
        Demo3 demo3 = new Demo3();
        int len = demo3.removeElement(nums, val);
        System.out.println(len);
        System.out.println(Arrays.toString(nums));//[0, 1, 3, 0, 4, 0, 4, 2]

    }

    public int removeElement(int[] nums, int val) {
        int solwIndex = 0;
        int len = nums.length;
        for (int qickIndex = 0; qickIndex < len; qickIndex++) {
            if(nums[qickIndex] != val){
                nums[solwIndex] = nums[qickIndex];
                solwIndex++;
            }
        }
        return solwIndex+1;
    }

}
